package com.ws.shop.entity;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.ws.shop.util.StringUtil;

public class AdminUser extends BaseEntity {
	private static final long serialVersionUID = -8317932680123125637L;
	private int userid;
	private String username;
	private String password;
	private String realname;
	private String descs;
	private int status;
	private int roleid;
	private int creatid;
	private Date creattime;
	
	private String crealname;//创建人名称
	private String rolename;//角色名称
	
	public final static String ADMIN_USER_LOGIN_SESSION_KEY = "ADMIN_USER_LOGIN";//管理员登录session 键名
	
	public final static Map<String,String> STATUS_DESCS = new HashMap<String,String>();
	
	static{
		STATUS_DESCS.put("1", "有效");
		STATUS_DESCS.put("0", "禁用");
	}
	
	public AdminUser(){}
	
	public AdminUser(String username,String password){
		this.username=username;
		this.password=password;
	}

	public String getCrealname() {
		return crealname;
	}

	public void setCrealname(String crealname) {
		this.crealname = crealname;
	}

	public String getRolename() {
		return rolename;
	}

	public void setRolename(String rolename) {
		this.rolename = rolename;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}


	public String getDescs() {
		return descs;
	}

	public void setDescs(String descs) {
		this.descs = descs;
	}


	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getUserid() {
		return userid;
	}

	public void setUserid(int userid) {
		this.userid = userid;
	}

	public int getCreatid() {
		return creatid;
	}

	public void setCreatid(int creatid) {
		this.creatid = creatid;
	}

	public Date getCreattime() {
		return creattime;
	}

	public void setCreattime(Date creattime) {
		this.creattime = creattime;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public int getRoleid() {
		return roleid;
	}

	public void setRoleid(int roleid) {
		this.roleid = roleid;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}
	public static String validUsername(String username, boolean nullable) {
		if(StringUtil.isEmpty(username)){
			if(nullable)
				return null;
			return "用户名不能为空";
		}
		if(!username.matches("[a-zA-Z0-9]{5,20}")){
			return "用户名只能为字母或数字，且长度在5-20位之间";
		}
		return null;
	}
	public static String validPassword(String password, boolean nullable) {
		if(StringUtil.isEmpty(password)){
			if(nullable)
				return null;
			return "密码不能为空";
		}
		if(password.length() < 6 || password.length() > 20){
			return "密码长度必须在6-20位之间";
		}
		return null;
	}
}
